<div class="row-content am-cf" ng-controller="sendmsgControl">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div id="app" class="widget am-cf">
                <form id="my-form" class="am-form tpl-form-line-form" method="post">
                    <div class="widget-body">
                        <fieldset>
                            <div class="widget-head am-cf">
                                <div class="widget-title am-fl">发送推送消息</div>
                            </div>
                            <!--<div class="tips am-margin-bottom am-u-sm-12">-->
                            <!--    <div class="pre">-->
                            <!--        <p>-->
                            <!--            注：模板消息只能发送给活跃用户，<a href="<?= url('market.push/user') ?>" target="_blank">查看活跃用户列表</a>，建议每次发送不超过10人。-->
                            <!--        </p>-->
                            <!--        <p>注：根据腾讯官方规定，滥用模板消息接口有被封号的风险，请谨慎使用！</p>-->
                            <!--    </div>-->
                            <!--</div>-->
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-3 am-form-label form-require">每次发送人数： </label>
                                <div class="am-u-sm-8 am-u-end">
                                    <input type="number" class="tpl-form-input" ng-model="model.rows" ng-init="model.rows=100" placeholder="请输入每次发送人数" required min="100" max="1000">
                                    <small>每次发送人数，自动循环调用<code>,</code> 例如：100</small>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-3 am-form-label form-require">
                                    模板消息ID <span class="tpl-form-line-small-title">Template ID</span>
                                </label>
                                <div class="am-u-sm-8 am-u-end">
                                    <input type="text" class="tpl-form-input" ng-model="model.tmplid" ng-init="model.tmplid='855MqgToeKsyvxLWmblbNkDaqwYg3cNNxjQA8pr_zHs'" placeholder="请输入模板消息ID" required>
                                    <small class="am-margin-left-xs">
                                        <a href="<?= url('store/setting.help/tplmsg') ?>"
                                           target="_blank">如何获取模板消息ID？</a>
                                    </small>
                                </div>
                            </div>
                            <div class="am-form-group am-padding-top">
                                <label class="am-u-sm-3 am-u-lg-3 am-form-label"> 活动名称 </label>
                                <div class="am-u-sm-8 am-u-end">
                                    <input type="text" class="tpl-form-input" ng-model="model.title" placeholder="请输入模板消息第1行的内容" required>
                                </div>
                            </div>
				
                            
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-3 am-form-label"> 活动内容</label>
                                <div class="am-u-sm-8 am-u-end">
                                    <input type="text" class="tpl-form-input" ng-model="model.content" placeholder="活动内容">
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-3 am-form-label"> 开始时间</label>
                                <div class="am-u-sm-8 am-u-end">
                                    <input type="text" class="tpl-form-input" ng-model="model.start" placeholder="开始时间:2020/12/11 00:00">
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-3 am-form-label"> 温馨提示</label>
                                <div class="am-u-sm-8 am-u-end">
                                    <input type="text" class="tpl-form-input" ng-model="model.hint" placeholder="温馨提示">
                                </div>
                            </div>
                            <div class="am-form-group am-padding-top">
                                <label class="am-u-sm-3 am-u-lg-3 am-form-label form-require"> 跳转的页面</label>
                                <div class="am-u-sm-8 am-u-end">
                                    <input type="text" class="tpl-form-input" ng-model="model.page" ng-init="model.page='pages/index/index?param=huodong'" placeholder="请输入小程序页面地址" required>
                                    <small class="am-margin-left-xs">
                                        <span>用户点击消息进入的页面,?和后面的参数不可更改<a href="<?= url('store/wxapp.page/links') ?>" target="_blank">小程序页面</a>，例如：<code>pages/index/index?param=huodong</code></span>
                                    </small>
                                </div>
                            </div>

                            <div class="am-form-group">
                                <div class="am-u-sm-9 am-u-sm-push-3 am-margin-top-lg">
                                    <!--<button type="submit" class="j-submit am-btn am-btn-secondary">提交</button>-->
                                    <button type="button" class="j-submit am-btn am-btn-secondary" ng-click="start()">{{btnTxt}}</button>
                                    <button type="button" class="j-submit am-btn am-btn-secondary" ng-click="stop()" ng-show="isStop==false">停止</button>
                                </div>
                            </div>
                        </fieldset>
                    </div>
                </form>

            </div>
        </div>
    </div>
</div>
<!--<script src="http://res.layui.com/layui/release/layer/dist/layer.js?v=3111"></script>-->
<script src="https://cdn.bootcss.com/angular.js/1.7.9/angular.min.js"></script>
<script>
	// angularjs
	var app = angular.module('app', []);
	app.controller('sendmsgControl', ['$scope','$http',function($scope,$http) {
		$scope.btnTxt = '发送';
		$scope.isStop = true; // 默认停止的
		$scope.model = {};
		$scope.model.times  = 1; // 默认第一页
		
		$scope.start = function(){
			if($scope.isStop == false){
				alert('当前正在发送中...');
				return false;
			}
			$scope.isStop = false;
			$scope.btnTxt = '发送中...';
			$scope.send();
		}
		$scope.stop = function(){
			$scope.isStop = true;
			$scope.btnTxt = '发送';
		}
		
		$scope.send = function(){
			if($scope.isStop == true){
				return alert('已停止');
			}
			if(!this.model.title){
				alert('请输入活动标题！');
				return false;
			}
			if(!this.model.content){
				alert('请输入活动内容！');
				return false;
			}
			if(!/^[2-9]{1}\d{3}\/\d{2}\/\d{2}\s\d{2}:\d{2}$/.test(this.model.start)){
				alert('活动开始时间格式:2020/04/01 15:00');
				return false;
			}
			if(!this.model.hint){
				alert('请输入活动提示！');
				return false;
			}
			if(!this.model.page){
				alert('请输入跳转地址！');
				return false;
			}
			if(!this.model.tmplid){
				alert('请输入订阅消息模板ID！');
				return false;
			}

			$http.post('https://kb.yinhua95.com/index.php?s=/api/wxapi/send&wxapp_id=10001',this.model,{}).then(res=>{
				console.log(res);
				
				$scope.model.times = $scope.model.times + 1;
				if(res.data == false){
					$scope.isStop = true;
					$scope.btnTxt = '发送';
					alert('发送完毕');
					return false;
				}
				if(res.data == true) $scope.send();
			})
		}
	}]);
</script>

<script>
    // $(function () {

    //     /**
    //      * 表单验证提交
    //      * @type {*}
    //      */
    //     $('#my-form').superForm({
    //         success: function (result) {
    //             var content = '';
    //             result.data['stateSet'].forEach(function (value) {
    //                 content += '<p>' + value + '</p>';
    //             });
    //             $.showModal({
    //                 title: '发送状态'
    //                 , closeBtn: 0
    //                 , area: '440px'
    //                 , btn: ['确定']
    //                 , btnAlign: 'c'
    //                 , content: '<div class="am-padding x-f-13">' + content + '</div>'
    //                 , yes: function () {
    //                     // window.location.reload();
    //                     return true;
    //                 }
    //             });


    //         }
    //     });

    // });
</script>
